Skip to contentMethod: setObject(String, Object)
1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.jena.query;
19:
20: import cz.cvut.kbss.ontodriver.PreparedStatement;
21: import cz.cvut.kbss.ontodriver.ResultSet;
22: import cz.cvut.kbss.ontodriver.jena.connector.StatementExecutor;
23: import cz.cvut.kbss.ontodriver.jena.exception.JenaDriverException;
24: import cz.cvut.kbss.ontodriver.util.StatementHolder;
25:
26: import java.util.Objects;
27:
28: public class JenaPreparedStatement extends JenaStatement implements PreparedStatement {
29:
30: private final StatementHolder holder;
31:
32: public JenaPreparedStatement(StatementExecutor executor, String sparql) {
33: super(executor);
34: this.holder = new StatementHolder(sparql);
35: if (holder.getStatement().isEmpty()) {
36: throw new IllegalArgumentException("Statement cannot be empty.");
37: }
38: holder.analyzeStatement();
39: }
40:
41: @Override
42: public ResultSet executeQuery() throws JenaDriverException {
43: ensureOpen();
44: return executeQuery(holder.assembleStatement());
45: }
46:
47: @Override
48: public void executeUpdate() throws JenaDriverException {
49: ensureOpen();
50: executeUpdate(holder.assembleStatement());
51: }
52:
53: @Override
54: public void setObject(String binding, Object value) {
55: ensureOpen();
56: Objects.requireNonNull(binding);
57: Objects.requireNonNull(value);
58: holder.setParameter(binding, value.toString());
59: }
60:
61: @Override
62: public void clearParameters() {
63: ensureOpen();
64: holder.clearParameters();
65: }
66: }